package artid.com.arttogo.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import artid.com.arttogo.R;
import artid.com.arttogo.bean.Spinfo;
import artid.com.arttogo.network.AppUtil;
import artid.com.arttogo.task.CallbackSky;
import artid.com.arttogo.utils.NetUtils;

public class SpecListAdapter extends BaseAdapter {
	private Context mContext;
	LayoutInflater mInflater;
	ViewHolder holder;
	CallbackSky cs;
	public List<Spinfo> list;
	String width;
	public SpecListAdapter(Context mContext) {
		this.mContext = mContext;
		mInflater = LayoutInflater.from(mContext);

		Map<String, String> map = NetUtils
				.getDisplayMetrics((Activity)mContext);
		width = String.valueOf(Integer.valueOf(map.get(NetUtils.DM_WIDTH))/2);
		list = new ArrayList<Spinfo>();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	public void setData(List<Spinfo> listin) {
		list = listin;
		notifyDataSetChanged();
	}
	public void addData(List<Spinfo> listin) {
		list.addAll(listin);
		notifyDataSetChanged();
	}
	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder vh = null;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = mInflater.inflate(R.layout.item_spec_list, null);

			vh.iv = (ImageView) convertView.findViewById(R.id.item_spec_iv);
			vh.state = (TextView) convertView.findViewById(R.id.item_spec_State);
			vh.name = (TextView) convertView.findViewById(R.id.item_spec_name);
			vh.lotnum = (TextView)convertView.findViewById(R.id.item_spec_reclot_num);
			vh.aucname = (TextView)convertView.findViewById(R.id.item_spec_aucname);
			vh.time = (TextView)convertView.findViewById(R.id.item_spec_time);
			vh.site = (TextView)convertView.findViewById(R.id.item_spec_site);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		Spinfo item = list.get(position);
		int status=item.getStatus();
		switch (status) {
			case 0:
				vh.state.setText("已结束");
				break;
			case 1:
				vh.state.setText("待预展");
				break;
			case 2:
				vh.state.setText("预展中");
				break;
			case 3:
				vh.state.setText("拍卖中");
				break;

			default:
				break;
		}
		Glide.with(mContext).load(item.getImgurl()+ AppUtil.picWidthUrl)
		.placeholder(R.drawable.ic_menu_rotate)
		.error(R.drawable.ic_menu_rotate).into(vh.iv);
		vh.name.setText(item.getTitle());
		vh.lotnum.setText(item.getLotrecord_num() +"件备案/"+item.getLot_num()+"件拍品");
		vh.aucname.setText(item.getSeller_name());
		vh.time.setText("拍卖时间："+item.getStart_time()+"-"+item.getEnd_time());
		vh.site.setText(item.getAddress());
		return convertView;
	}

	class ViewHolder {
		TextView state,name,lotnum,aucname,time,site;
		ImageView iv;
	}
}
